package com.cirkana.viewer.data;

import java.io.InputStream;
import java.util.List;
import java.util.Properties;

import com.cirkana.config.CirkanaConfig;
import com.cirkana.config.CirkanaConfigException;

public class LocalDataConfig extends CirkanaConfig {

	protected static final String PROP_DATABASE_NAME = "database.name";
	protected static final String PROP_DATABASE_VERSION = "database.version";
	protected static final String PROP_DATABASE_DELETE_BEFORE = "database.delete.before";
	protected static final String PROP_SENTENCES_CREATE = "sentences.create";
	protected static final String PROP_SENTENCES_INITIAL = "sentences.initial";

	private final String dataBaseName;
	private int dataBaseVersion;
	private boolean deleteDataBaseBefore;
	private List<String> createSentences;
	private List<String> initialSentences;

	public LocalDataConfig(InputStream propertiesInputStream) throws CirkanaConfigException {
		Properties p = loadProperties(propertiesInputStream);
		this.dataBaseName = extractStringProperty(p, PROP_DATABASE_NAME);
		this.dataBaseVersion = extractIntegerProperty(p, PROP_DATABASE_VERSION);
		this.deleteDataBaseBefore = extractBooleanProperty(p, PROP_DATABASE_DELETE_BEFORE, false);
		this.createSentences = extractStringListProperties(p, PROP_SENTENCES_CREATE);
		this.initialSentences = extractStringListProperties(p, PROP_SENTENCES_INITIAL);
	}

	protected String getLocalDataBaseName() {
		return this.dataBaseName;
	}

	protected int getLocalDataBaseVersion() {
		return this.dataBaseVersion;
	}

	protected boolean mustDeleteDataBaseBefore() {
		return this.deleteDataBaseBefore;
	}

	protected List<String> getCreateSentences() {
		return this.createSentences;
	}

	protected List<String> getInitialSentences() {
		return this.initialSentences;
	}
}
